<?
require("config.php");

require($rela_path . "bin/country.php");

$location_status .= " | Enquire";

$show_backnav = "order_menu";

$menutype = 2;

if (NULL!=$action){

   $Query = "delete from $table where id=$id LIMIT 1";

   myQuery($Query);

   $Query = "delete from $table1 where no='$Code'";

   myQuery($Query);


   header("location:" . $rela_path . "share/msg.php?v=27");

   exit();

}


if (!checkRecord($table,$id)){

	header("location:" . $rela_path . "share/msg.php?v=9002");
	exit();

}


$Query = "SELECT 
	no,
	date,
	customer_code,
	company,
	title,
	contact,
	address,
	zip,
	city,
	country,
	tel,
	fax,
	email,
	website,
	business,
	profile
FROM $table WHERE id=$id";

$r = myQuery($Query);

	$Code=			$r[0][0];
	$Date=			$r[0][1];
	$CustomerCode=	$r[0][2];
	$Company=		$r[0][3];
	$Title=			$r[0][4];
	$Contact=		$r[0][5];
	$Address=		$r[0][6];
	$Zip=			$r[0][7];
	$City=			$r[0][8];
	$Country=		$r[0][9];
	$Tel=			$r[0][10];
	$Fax=			$r[0][11];
	$Email=			$r[0][12];
	$Website=		$r[0][13];
	$Business=		$r[0][14];
	$Profile=		$r[0][15];


//Currency
$Query = "SELECT currency FROM cus_basic WHERE contact='$Contact' AND company='$Company' LIMIT 1";
$c=myQuery($Query);

if (!$c) {
	$currency="usd";
}else{
	$currency = $c[0][0];
}



if (!$header_file) $header_file = "inc/header.php";
if (!$footer_file) $footer_file = "inc/footer.php";

require($rela_path . $header_file);

?>

<form action="" method="post" name="form1">  

<!--hidden filed-->
<input name="action" type="hidden" value="delete">
<input name="id" type="hidden" value="<?print($id)?>">
<input name="Code" type="hidden" value="<?print($Code)?>">

<table width="95%" border="0" align="center">
  <tr> 
    <td width="579" valign="top" height="143">
      <br>
      <table border="0" cellspacing="0" cellpadding="2">
        <tr> 
          <td width="137" class="tdheader">No :</td>
          <td width="455"><?print($Code)?></td>
        </tr>
        <tr> 
          <td width="137" class="tdheader">Date :</td>
          <td width="455"><?print(substr($Date,0,4) . "-" . substr($Date,4,2) . "-" . substr($Date,6,2))?></td>
        </tr>
        <tr> 
          <td width="137" class="tdheader">Customer Code :</td>
          <td width="455"><?print($CustomerCode)?></td>
        </tr>
        <tr> 
          <td width="137" height="3" class="tdheader">Company :</td>
          <td width="455" height="3"><?print($Company)?></td>
        </tr>
        <tr> 
          <td width="137" class="tdheader">Contact Person :</td>
          <td width="455"><?print("$Title $Contact")?></td>
        </tr>
        <tr> 
          <td width="137" class="tdheader">Address :</td>
          <td width="455"><?print($Address)?></td>
        </tr>
        <tr> 
          <td width="137" class="tdheader">Zip Code : </td>
          <td width="455"><?print($Address)?></td>
        </tr>
        <tr> 
          <td width="137" class="tdheader">City :</td>
          <td width="455"><?print($City)?></td>
        </tr>
        <tr> 
          <td width="137" class="tdheader">Country :  </td>
          <td width="455"><?print($Country)?></td>
        </tr>
        <tr> 
          <td width="137" class="tdheader">Tel :</td>
          <td width="455"><?print($Tel)?></td>
        </tr>
        <tr> 
          <td width="137" class="tdheader">Fax :</td>
          <td width="455"><?print($Fax)?></td>
        </tr>   
        <tr> 
          <td width="137" class="tdheader">Email :</td>
          <td width="455"><?print($Email)?></td>
        </tr>
        <tr> 
          <td width="137" class="tdheader">Website :</td>
          <td width="455"><?print($Website)?></td>
        </tr> 
        <tr> 
          <td width="137" class="tdheader">Nature of Business :  </td>
          <td width="455"><?print($Business)?></td>
        </tr> 
        <tr> 
          <td width="137" class="tdheader">Message :  </td>
          <td width="455"><?print($Profile)?></td>
        </tr> 
        <tr> 
          <td width="137">&nbsp;</td>
          <td width="455">&nbsp;</td>
        </tr>
        <tr> 
          <td colspan="2"> 

<?
$Query = "SELECT 
no,
pro_code,
pro_name,
pro_color,
pro_size,
unit_price,
qty 
FROM $table1 WHERE no='$Code'";
$r=myQuery($Query);

?>


        <table width="95%" border="0" cellpadding="0" cellspacing="1" class="tb">
          <tr class="tbheader"> 
            <td> <div align="center" class="tdheader">No.</div></td>
            <td> <div align="center" class="tdheader">Product Code</div></td>
            <td> <div align="center" class="tdheader">Product Name</div></td>
			<td> <div align="center" class="tdheader">Color</div></td>
			<td> <div align="center" class="tdheader">Size</div></td>
            <td> <div align="center" class="tdheader">Unit Price</div></td>
            <td> <div align="center" class="tdheader">Qty</div></td>
            <td> <div align="center" class="tdheader">Amount</div></td>
          </tr>

<?
$total_qty = 0;
$total_price = 0;
	

	for ($i=0;$i<count($r);$i++){
	
	$subtotal = $r[$i][5]*$r[$i][6];
	$total_qty += $r[$i][6];
	$total_price += $subtotal;
	?>
          <tr class="tbcontent1"> 
            <td><?print($i+1)?></td>
            <td><?print($r[$i][1])?></td>
            <td><?print($r[$i][2])?></td>
			<td><?print($r[$i][3])?></td>
			<td><?print($r[$i][4])?></td>
            <td> <div align="right"><?print($r[$i][5])?></div></td>
            <td> <div align="right"><?print($r[$i][6])?></div></td>
            <td> <div align="right"><?print(Number_format($subtotal,2))?></div></td>
          </tr>
<?}?>



          <tr> 
            <td colspan="8" class="tbcontent1" height=30><div align="right"><b>Total Amount : <?print("($currency)" . Number_format($total_price,2))?></b></div></td>
          </tr>
        </table>


          </td>
        </tr>
      </table>
      <br>
      <br>
    </td>

  </tr>
</table>

</form>

<br>
<br>
<br>
<?
require($rela_path . $footer_file);
?>
